#ifndef __PHLOGGER_H__
#define __PHLOGGER_H__

#ifdef WIN32
#pragma warning(push)
#pragma warning(disable: 4996)
#pragma warning(disable: 4995)
#endif

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <stdarg.h>
#include <time.h>
#include "DebugOutputLog.h"
#include "loggerdefine.h"

#ifndef _LOG_OUPUT_TO_CONSOLE
  #ifdef WIN32
	#ifndef USE_DLL_ORAYLOG
      #include "phlogger_linux.h"
    #else
      #include "phlogger_win32.h"
    #endif
  #elif __APPLE__
	#include "phlogger_apple.h"
  #elif __ANDROID__
    #include "phlogger_android.h"
  #else
	#include "phlogger_linux.h"
  #endif
#else
  #ifdef __ANDROID__
    #include "phlogger_android.h"
  #else
	static bool WriteLog_C(int evt,const char* str,...)
	{
        //filter event
		if(!(evt & logConfigs)) return false;
        
        //string time 
        char sztime[32] = "";
        time_t now = time(NULL);
        struct tm *tm = localtime(&(now));
        if (tm) strftime(sztime, sizeof(sztime),"%Y-%m-%d %H:%M:%S\t", tm);

        //parse variable param
		char *fmtstr = NULL;
		int len = 0;
		va_list   varg;   
		va_start(varg,   str);
		len = _vscprintf( str, varg );
		fmtstr = new char[len+1];
		fmtstr[len] = 0;
		vsnprintf(fmtstr,len, str,   varg);   
		va_end(varg); 

        OutputStringF("%s\t%s\t%s\r\n", sztime, string_event(evt), fmtstr);
        //OutputStringF("[%d]\t%s\t%s\t%s\r\n", GetCurrentThreadId(),sztime, string_event(evt), fmtstr); //add thread id for window
        //OutputStringF("[%d]%s\t%s\t%s\r\n", pthread_self(),sztime, string_event(evt), fmtstr);         //add thread id for linux

		delete [] fmtstr;

		return true;
	}

	static void SetLogPath_C(const char* szPath) {}
    static void OpenLogger_C(const char* name){}
    static void SetMaxSize_C(unsigned long size) {}
    inline void SetLogFlag(int) {}

	#define WriteLog WriteLog_C
	#define SetLogPath SetLogPath_C
    #define OpenLogger OpenLogger_C
    #define SetMaxSize SetMaxSize_C
  #endif
#endif //_LOG_OUPUT_TO_CONSOLE

#ifdef DEBUG
#  define WriteTestLog    WriteLog(LOG_INFO, ">>> [test] call %s [%s:%d]", __FUNCTION__, __FILE__, __LINE__)
#else
#  define WriteTestLog    
#endif

#ifdef WIN32
#pragma warning(pop)
#endif

#endif //__PHLOGGER_H__

